package defaultPackage;
import java.awt.*;
public class Cursor
{
	public int x = (MainClass.windowXSize - 200) / 2;
	public int y = MainClass.windowYSize / 2;
	boolean active = false,left,right,up,down;
	MainClass main;
	Camera camera;
	int acceleration = 1,numOnTile = 0;
	ObjectType objectType = null;
	
	public Cursor(MainClass main,Camera camera)
	{
		this.main = main;
		this.camera = camera; 
	}
	
	public void draw (Graphics g)
	{
		if (active)
		{
			g.setColor(Color.green);
			g.drawRect(x,y,10,10);
		}
	}
	
	public void setActive(boolean active)
	{
		this.active = active;
	}
	public boolean isActive()
	{
		return active;
	}
	
	public void cursorLeft(boolean left)
	{
		if (x == camera.getX())
			camera.cameraLeft();
		if (x >= camera.getX() +10)
			x -= 10 * acceleration;
	}
	
	public void cursorRight(boolean right)
	{
		if (x == camera.getX()+ (MainClass.windowXSize - 210))
			camera.cameraRight();
		if (x <= camera.getX()+ (MainClass.windowXSize - 220))
			x += 10 * acceleration;
	}
	
	public void cursorUP(boolean up)
	{
		if (y == camera.getY() + 20)
			camera.cameraUp();
		if (y >= camera.getY() + 30)
			y -= 10 * acceleration;
	}
	
	public void cursorDown(boolean down)
	{
		if (y == camera.getY() + (MainClass.windowYSize - 10))
			camera.cameraDown();
		if (y <= camera.getY() + (MainClass.windowYSize - 20-100))
			y += 10 * acceleration;
	}
	
	public int getX()
	{
		return x;
	}
	
	public int getY()
	{
		return y;
	}
	
	public void setAccelerated(boolean accelerated)
	{
		if (accelerated)
			acceleration = 2;
		else
			acceleration = 1;
	}
	
	public Object createObject()
	{
		Resources.setResources(Resources.getResources() - objectType.getValue());
		return new Object (x,y,objectType,main.grid);
	}
	
	public void setObjectType(ObjectType type)
	{
		this.objectType = type;
	}
	
	public ObjectType getObjectType()
	{
		return objectType;
	}
	
	public int checkNumOnTile()
	{
		numOnTile = 0;
		for (Object o:main.objectmanager.objects)
		{
			if (o.getX() == x && o.getY() == y)
			{
				numOnTile++;
			}
		}
		for (Person p:main.people.people)
		{
			if (p.getX() == x/10 && p.getY() == y/10)
			{
				numOnTile++;
			}
		}
		return numOnTile;
	}
}
